import { defineConfig } from 'vite'
import path from 'node:path'
import reactRefresh from '@vitejs/plugin-react-refresh';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [reactRefresh()],
  root: './',

  base: '/runtime',

  publicDir: 'public',
  resolve: {
    alias: [
      { find: /^react$/, replacement: path.join(__dirname, 'node_modules/react/index.js') },
      { find: /^react-dom$/, replacement: path.join(__dirname, 'node_modules/react-dom/index.js') },
      {
        find: /^@tmagic\/utils\/resetcss.css/,
        replacement: path.join(__dirname, '../../node_modules/@tmagic/utils/src/resetcss.css'),
      },
      { find: /^@tmagic\/utils/, replacement: path.join(__dirname, '../../node_modules/@tmagic/utils/src/index.ts') },
      { find: /^@tmagic\/core/, replacement: path.join(__dirname, '../../node_modules/@tmagic/core/src/index.ts') },
      { find: /^@tmagic\/schema/, replacement: path.join(__dirname, '../../node_modules/@tmagic/schema/src/index.ts') },
      { find: /^@data-source/, replacement: path.join(__dirname, '../../node_modules/@tmagic/data-source/src') },
      { find: /^@tmagic\/data-source/, replacement: path.join(__dirname, '.../../node_modules/@tmagic/data-source/src/index.ts') },
    ],
  },
  server: {
    host: '0.0.0.0',
    port: 8078,
    strictPort: true,
  },
  build: {
    sourcemap: true,

    cssCodeSplit: false,

    rollupOptions: {
      input: {
        page: './page/index.html',
        playground: './playground/index.html',
      },
      output: {
        entryFileNames: 'assets/[name].js',
      },
    },
  },
})
